<template>
  <XtxBread>
    <XtxBreadItem>首页</XtxBreadItem>
    <XtxBreadItem v-if="category.top" :to="`/category/${category.top.id}`">{{category.top.name}}</XtxBreadItem>
    <transition name="fade-right" mode="out-in">
      <XtxBreadItem v-if="category.sub" :to="`/category/sub/${category.sub.id}`">{{category.sub.name}}</XtxBreadItem>
    </transition>
  </XtxBread>
</template>

<script>
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import { computed } from 'vue'
export default {
  name: 'SubBread',
  setup() {
    // 获取数据
    const store = useStore()
    const route = useRoute()
    const category = computed(() => {
      let cate = {}
      store.state.category.list.forEach(top => {
        if (top.children) {
          top.children.forEach(sub => {
            if (sub.id === route.params.id) {
              cate.top = { name: top.name, id: top.id }
              cate.sub = { name: sub.name, id: sub.id }
            }
          })
        }
      })
      return cate
    })
    return { category }
  }

}
</script>

<style>
</style>